package com.google.code.jmarias.server.phases;

import com.google.code.jmarias.common.action.DealFiveCardsAction;
import com.google.code.jmarias.common.action.DealSevenCardsAction;
import com.google.code.jmarias.common.action.SignedAction;
import com.google.code.jmarias.server.tcp.MariasGame;
import com.google.code.jmarias.common.NewPlayer;
import com.google.code.jmarias.common.NewTable;

/**
 *
 * @author Ondrej Michal
 */
public class DealingPhase extends NewAbstractPhase {

    public DealingPhase(NewPlayer playingNow) {
        super(playingNow);

        addListener(new ActionListener(null) {

            @Override
            protected NewAbstractPhase processAction(SignedAction action, NewTable table) {
                // kontrola prichozi akce - ok, trivialne splneno, protoze je null

                broadcast(new SignedAction(new DealSevenCardsAction(table.getDeck().getCards(7), table.getPlayer(MariasGame.forehand).getClient())), table.getPlayer(MariasGame.forehand));
                broadcast(new SignedAction(new DealFiveCardsAction(table.getDeck().getCards(5), table.getPlayer(MariasGame.left).getClient())), table.getPlayer(MariasGame.left));
                broadcast(new SignedAction(new DealFiveCardsAction(table.getDeck().getCards(5), table.getPlayer(MariasGame.right).getClient())), table.getPlayer(MariasGame.right));

                return new TrumpPickPhase(table.getPlayer(MariasGame.forehand));
            }
        });
    }

}
